package com.kkd.kkdapp.db.app.model;

import com.kkd.kkdapp.db.annotate.EADBField;
import com.kkd.kkdapp.db.annotate.EADBField.EADBFieldMode;
import com.kkd.kkdapp.db.annotate.EADBField.EADBFieldType;
import com.kkd.kkdapp.db.app.EADBHelper;
import com.kkd.kkdapp.db.base.EABaseModel;

public class PdfUrlModel extends EABaseModel{

	private static final String TABLE_NAME = PdfUrlModel.class.getSimpleName();
	
	@EADBField(mode = EADBFieldMode.NotNull,type = EADBFieldType.Text )
	public String fileMd5;
	@EADBField(type = EADBFieldType.Text)
	public String url;
	
	
	public static long insert(String fileMd5, String url) {
		PdfUrlModel curPdf = EADBHelper.getInstance().queryTopOne(PdfUrlModel.class, " fileMd5=? ",
				new String[] { fileMd5 });
		if(curPdf!=null){
			EADBHelper.getInstance().delete(TABLE_NAME," fileMd5=? ",new String[] { fileMd5 });
		}
		PdfUrlModel newPdf = new PdfUrlModel();		
		newPdf.fileMd5 = fileMd5;
		newPdf.url = url;
		return EADBHelper.getInstance().saveBindId(newPdf);
	}
	
	public static String queryUrlByFileMd5(String fileMd5) {
		String url = null;
		if(EADBHelper.getInstance()!=null){
			PdfUrlModel pdf = EADBHelper.getInstance().queryTopOne(PdfUrlModel.class, " fileMd5=? ", new String[] { fileMd5 });
			if(pdf!=null)
				url = pdf.url;
		}
		return url;
	}
	

}
